package it.polimi.traveldream.web.beans.customer;

import it.polimi.traveldream.ejbclient.dtos.ParticipationDTO;

import it.polimi.traveldream.ejbclient.eaos.AccountServiceEAO;
import it.polimi.traveldream.ejbclient.eaos.ParticipationServiceEAO;
import it.polimi.traveldream.utils.exceptions.NotSuchUserException;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="listCustomerParticipatedTravelPackages")
@RequestScoped
public class ListParticipatedPackages {
	@EJB
	private ParticipationServiceEAO pService;
	@EJB
	private AccountServiceEAO aService;
	private List<ParticipationDTO> participations;

	public ListParticipatedPackages() {
	}
	
	@PostConstruct
	public void init() {
		try {
			participations = pService.getUserParticipations(aService.getCurrentUser().getId(), false);
		} catch (NotSuchUserException e) {
			participations = new ArrayList<ParticipationDTO>();
		}
		try {
			participations.addAll(pService.getUserParticipations(aService.getCurrentUser().getId(), true));
		} catch (NotSuchUserException e) {
		}
	}

	public List<ParticipationDTO> getParticipations() {
		return participations;
	}

	public void setParticipations(List<ParticipationDTO> participations) {
		this.participations = participations;
	}

}
